﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region CMS_Columns实体类
public class CMS_Columns
{
	private string m_ColumnID;
	private string m_ColumnName;
	private string m_ParentID;
	private int m_Disabled;
	private string m_SequenceNo;
	private string m_Tag;
	
	public CMS_Columns ()
	{
		m_ColumnID="";
		m_ColumnName="";
		m_ParentID="";
		m_Disabled=0;
		m_SequenceNo="";
		m_Tag="";
	}
	
	public string ColumnID
	{
		get{return m_ColumnID;}
		set{m_ColumnID=value;}
	}
	public string ColumnName
	{
		get{return m_ColumnName;}
		set{m_ColumnName=value;}
	}
	public string ParentID
	{
		get{return m_ParentID;}
		set{m_ParentID=value;}
	}
	public int Disabled
	{
		get{return m_Disabled;}
		set{m_Disabled=value;}
	}
	public string SequenceNo
	{
		get{return m_SequenceNo;}
		set{m_SequenceNo=value;}
	}
	public string Tag
	{
		get{return m_Tag;}
		set{m_Tag=value;}
	}
}
#endregion

#region CMS_Columns管理类
public partial class LogicLayer
{
	public bool AddCMS_Columns(CMS_Columns theCMS_Columns)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into CMS_Columns (ColumnID,ColumnName,ParentID,Disabled,SequenceNo,Tag) values (@ColumnID,@ColumnName,@ParentID,@Disabled,@SequenceNo,@Tag)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@ColumnID", DbType.String, theCMS_Columns.ColumnID);
			db.AddInParameter(cmd, "@ColumnName", DbType.String, theCMS_Columns.ColumnName);
			db.AddInParameter(cmd, "@ParentID", DbType.String, theCMS_Columns.ParentID);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theCMS_Columns.Disabled);
			db.AddInParameter(cmd, "@SequenceNo", DbType.String, theCMS_Columns.SequenceNo);
			db.AddInParameter(cmd, "@Tag", DbType.String, theCMS_Columns.Tag);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddCMS_Columns:" + ex.Message );
			return false;
		}
	}
	
	public CMS_Columns GetCMS_ColumnsFromDataReader(IDataReader dataReader)
	{
		try
		{
			CMS_Columns result = new CMS_Columns();
			
			if (dataReader["ColumnID"] != null && dataReader["ColumnID"] != System.DBNull.Value )
				result.ColumnID = (string)dataReader["ColumnID"];
			if (dataReader["ColumnName"] != null && dataReader["ColumnName"] != System.DBNull.Value )
				result.ColumnName = (string)dataReader["ColumnName"];
			if (dataReader["ParentID"] != null && dataReader["ParentID"] != System.DBNull.Value )
				result.ParentID = (string)dataReader["ParentID"];
			if (dataReader["Disabled"] != null && dataReader["Disabled"] != System.DBNull.Value )
				result.Disabled = (int)dataReader["Disabled"];
			if (dataReader["SequenceNo"] != null && dataReader["SequenceNo"] != System.DBNull.Value )
				result.SequenceNo = (string)dataReader["SequenceNo"];
			if (dataReader["Tag"] != null && dataReader["Tag"] != System.DBNull.Value )
				result.Tag = (string)dataReader["Tag"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderCMS_Columns:" + ex.Message);
			return null;
		}
	}
	
	public CMS_Columns GetCMS_Columns(string ColumnID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From CMS_Columns where ColumnID=@ColumnID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@ColumnID", DbType.String, ColumnID);
			
			CMS_Columns result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetCMS_ColumnsFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetCMS_Columns:" + ex.Message);
			return null;
		}
	}
	
	public bool DelCMS_Columns(string ColumnID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From CMS_Columns where ColumnID=@ColumnID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@ColumnID", DbType.String, ColumnID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelCMS_Columns:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateCMS_Columns(CMS_Columns theCMS_Columns)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update CMS_Columns set ColumnName=@ColumnName,ParentID=@ParentID,Disabled=@Disabled,SequenceNo=@SequenceNo,Tag=@Tag where ColumnID=@ColumnID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@ColumnName", DbType.String, theCMS_Columns.ColumnName);
			db.AddInParameter(cmd, "@ParentID", DbType.String, theCMS_Columns.ParentID);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theCMS_Columns.Disabled);
			db.AddInParameter(cmd, "@SequenceNo", DbType.String, theCMS_Columns.SequenceNo);
			db.AddInParameter(cmd, "@Tag", DbType.String, theCMS_Columns.Tag);
			db.AddInParameter(cmd, "@ColumnID", DbType.String, theCMS_Columns.ColumnID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateCMS_Columns:" + ex.Message);
			return false;
		}
	}
	
	public List<CMS_Columns> ListCMS_Columns()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from CMS_Columns";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<CMS_Columns> result = new  List<CMS_Columns>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					CMS_Columns obj = GetCMS_ColumnsFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListCMS_Columns:" + ex.Message);
			return null;
		}
	}
	
}
#endregion